//1658.将x减到 0的最小操作数  https://leetcode.cn/problems/minimum-operations-to-reduce-x-to-zero/description/

class Solution {
    public int minOperations(int[] nums, int x) {
        //滑动窗口＋逆向思维
        int sum =0;
        for(int num : nums){
            sum+=num;
        }
        if(sum<x){
            return -1;
        }
        int targ = sum - x;
        //开始滑动
        int left = 0;
        int s=0;
        int res = -1;
        for(int right = 0;right<nums.length;right++){
            s+=nums[right];
            while(s>targ){
                s-=nums[left];
                left++;
            }
            if(s == targ){
                res = Math.max(res,right-left+1);
            }
        }
        return res>=0 ? nums.length-res : -1;

    }
}

//26.删除有序数组中的重复项  https://leetcode.cn/problems/remove-duplicates-from-sorted-array/description/

class Solution {
    public int removeDuplicates(int[] nums) {
      if(nums == null || nums.length ==0) return 0;
      int p=0;
      int q=1;
      while(q<nums.length){
        if(nums[p]!=nums[q]){
            nums[p+1]=nums[q];
            p++;
        }
        q++;
      }  
      return p+1;
    }
}